package com.ruoyi.controller;

import com.ruoyi.domain.T02;
import com.ruoyi.domain.T11DAO;
import com.ruoyi.common.result.Result;
import com.ruoyi.mapper.T02TMapper;
import com.ruoyi.mapper.T09TMapper;
import com.ruoyi.mapper.T10TMapper;
import com.ruoyi.mapper.T11TMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class IndexController {
    //首页显示三大要素

    @Resource
    T09TMapper t09TMapper;
    @Resource
    T02TMapper t02TMapper;
    @Resource
    T10TMapper t10TMapper;
    @Resource
    T11TMapper t11TMapper;


    @GetMapping("/yydindex")
    public Result<?> yydindex(){
        Map<String , String> map = new HashMap<>();
        map.put("chuli", t09TMapper.getT09Count()+"");
        T02 t02 = t02TMapper.selectT02();
        map.put("yue",t02.getF0203()+"");
        map.put("shengyu",t02.getF0204()+"");
        return Result.success(map,"");
    }


    //收入分析数据

    @RequestMapping("/yydsou")
    public Result<?> yydsou() throws ParseException {
        Map<String , String> map = new HashMap<>();
        map.put("profit", t10TMapper.selectT10Sum()+"");
        Date currentDate = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = formatter.parse(formatter.format(currentDate));
        java.sql.Date sqlDate= new java.sql.Date(date.getTime());
        System.out.println(sqlDate);
        map.put("huoli", t10TMapper.selectT10(sqlDate)+"");

        LocalDate yesterday = LocalDate.now().minusDays(1);
        DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formattedYesterday = yesterday.format(formatter1);
        Date date1 = formatter.parse(formattedYesterday);
        java.sql.Date sqlDate1= new java.sql.Date(date1.getTime());
        map.put("zz",t10TMapper.selectT10(sqlDate) - t10TMapper.selectT10(sqlDate1)+"");
        map.put("max",t10TMapper.MaxF1102());
        List<T11DAO> list = t11TMapper.selectT11(sqlDate);
        if (list.size() >= 1){
            map.put("khxf1",list.get(0).getF1102());
            map.put("khxf1f", String.valueOf(list.get(0).getF01103()));
        }
        if(list.size() >= 2){
            map.put("khxf2",list.get(1).getF1102());
            map.put("khxf2f", String.valueOf(list.get(1).getF01103()));
        }
        if(list.size() >= 3){
            map.put("khxf3",list.get(2).getF1102());
            map.put("khxf3f", String.valueOf(list.get(2).getF01103()));
        }
        return Result.success(map,"");
    }


//    今日数据客户消费板块

    @RequestMapping("/yydjinkh")
    public Result<?> yydjinkh(){

        return Result.success();
    }

}
